package org.kymjs.kjframe.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by tse on 2015-05-11
 */

public abstract class Common2TypeAdapter<T> extends BaseAdapter {
    protected Context mContext;
    protected List<T> mDatas;
    protected LayoutInflater mInflater;
    private int layoutId;
    private int layoutId2;


    public Common2TypeAdapter(Context context, List<T> datas, int layoutId, int layoutId2) {
        this.mContext = context;
        mInflater = LayoutInflater.from(context);
        this.mDatas = datas;
        this.layoutId = layoutId;
        this.layoutId2 = layoutId2;
    }


    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public T getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        if (getItemViewType(position) == 0) {

            ViewHolder holder = ViewHolder.get(mContext, convertView, parent,
                    layoutId, position);
            convert(holder, getItem(position), position);
            return holder.getConvertView();
        } else if (getItemViewType(position) == 1) {

            ViewHolder holder = ViewHolder.get(mContext, convertView, parent,
                    layoutId2, position);
            convertType2(holder, getItem(position), position);
            return holder.getConvertView();
        } else {
            ViewHolder holder = ViewHolder.get(mContext, convertView, parent,
                    layoutId, position);
            convert(holder, getItem(position), position);
            return holder.getConvertView();

        }

    }


    public abstract void convert(ViewHolder holder, T t, int position);

    public abstract void convertType2(ViewHolder holder, T t, int position);

}